
#pragma once

#include "GActivity.h"
#include "Common/Timer/TimerAxis.h"
#include "Common/Event/Event.h"
#include "Common/EventDefine.h"

class GActivityGoblin : public ITimerHandler, public IEventExecuteSink, public GActivity
{
	enum
	{
		ETimer_ID_Check = 1,
		ETimer_ID_BossDie = 2,
	};
	typedef unordered_map<uint64_t, GoblinNpcState> GoblinNpcMap;
public:
	GActivityGoblin();
	virtual ~GActivityGoblin();
public:
	virtual void Init(uint32_t activityId);
	virtual void UnInit();
	virtual bool	Update();
	virtual int32_t	GetType() { return ATI_GOBLIN; };
	virtual void InitUnionParam(uint32_t unionId, uint32_t sceneId, uint32_t mapId, int32_t unionLev, int32_t averageLev, int32_t collegaLev, int32_t vaultLev);
	//玩家进入工会驻地
	virtual void OnEnterUnionHome(CharIDType charId);
	//工会等级更新
	virtual void OnUnionLevUpdate(int32_t unionLev);
	//npc对话
	virtual int32_t TalkToNpc(Player *pPlayer, uint64_t npcCid, int32_t reply,int8_t &type);
	//////////////////////////////////////////////////////////////////////////
	virtual void OnTimer(uint32_t nTimerID);
	//////////////////////////////////////////////////////////////////////////
	virtual void OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
protected:	
	virtual void	OnActivityStart();
	virtual void	OnActivityStop();
private:
	void Clear();									//清空	
	void ClearUnionParam();							//清空工会参数
	void FreshNpc(uint64_t curTime);				//刷新NPC
	void DelNpc(uint64_t npcCid);					//移除NPC
	void AddPlanRelate(uint64_t planUid,uint64_t npcCid);	//增加位面关联的NPC
	void DelPlanRelate(uint64_t planUid);					//删除位面关联的NPC
	uint64_t GetPlanRelate(uint64_t planUid);				//获取位面关联的NPC
	bool FreshMonster(uint64_t npcCid, Point3<float> midPos, uint32_t teamId, uint32_t areaId, SET_UINT64 &setChars);//刷新怪物
	void FreshBoss(int32_t averageLev);									//刷新boss怪
	int32_t NpcNum();									//npc数量
	void GetCanFreshArea(SET_UINT32 &setArea);			//获取可以刷新区域ID
	GoblinNpcState *GetGoblinNpc(uint64_t npcCid);		//根据NPC cid 获取NPC信息
	GoblinNpcState *GetGoblinNpcByAreaId(uint32_t areaId);	//根据 Npc 所在区域ID 获取NPC信息
	void CheckNpc(uint64_t curTime);						//检查NPC生存时间
	int32_t StealNum();										//偷取的工会资金
	void NpcLifeEnd(uint64_t npcCid,bool notify);			//npc生命结束
	void NotifyStealMoney();								//通知偷取工会资金
	void NotifySceneNpcState(ActivityNotifyNpcState &rsp);					//通知NPC状态
	void NotifyPlayerNpcState(Player *pPlayer, ActivityNotifyNpcState &rsp);	//通知玩家NPC状态
	void SetNpcStateProto(ActMultNpcStateProto &rsp, GoblinNpcState &npcState, uint64_t curTime);
	void NotifySceneNpcDie(SET_UINT64 &setDie);								//通知NPC死亡
	bool GetSceneCidByTeamId(uint32_t teamId,SET_UINT64 &setChars);			//获取场景内指定队伍ID的玩家
	int32_t LeftSec(uint64_t curTime,uint64_t startTime);	//剩余时间
	void SubscribeBossEvent();		//订阅boss相关事件
	void OnBossDie(CharIDType killerCid);
	void OnMonsDrop(DieEvent *pDieEvent); //怪物掉落
	void RecycleNpcAndMonster();
	void FindBrushPos(Point3<float> midPos, int32_t count, VecPoint3 &vecPos);
	Monster *GetSceneMonster(CharIDType cid);			//获取怪物
	Npc *GetSceneNpc(CharIDType cid);					//获取npc
	Creature*GetSceneCreature(CharIDType cid);			//获取玩家
	Player* GetScenePlayer(CharIDType cid);				//获取玩家
	void AddHuoyue(SET_UINT64 &setCid);					//增加哥布林活跃度
	void AddWaitPlan(uint64_t planUid);					//增加等待销毁的位面
	void DelWaitPlan(uint64_t planUid);					//移除等待销毁的位面
	void OnPlanDestory();								//销毁位面
private:
	GoblinCfg m_cfg;
	uint32_t m_unionId;				//工会ID
	uint32_t m_sceneId;				//场景ID
	uint32_t m_mapId;				//地图ID
	int32_t m_lev;					//工会等级
	int32_t m_averageLev;			//工会精英平均等级
	int32_t m_vaultLev;				//工会金库等级
	MAP_UINT64_UINT64 m_mapPlanRelate; //位面关联的NPC plan uid - npcid
	GoblinNpcMap m_mapNpc;			//npc信息
	bool m_freshBoss;				//是否已刷新boss怪
	uint64_t m_bossCid;				//boss cid
	SET_UINT64 m_setHarmChar;		//对boss产生伤害的玩家
	SET_UINT64 m_setFreshMonster;	//刷新的怪物CID
	int32_t m_recycleNum;			//已回收的NPC数量
	int32_t m_freshNum;				//已经刷新的NPC数量
	bool m_bNotifyMonsAllDie;		//是否有通知中心服所有的怪物死亡
	SET_UINT64 m_setWaitPlan;		//等待销毁的位面
	
};